#!/bin/bash
source tools/getenv.sh



function mySupervisorServiceRestart() {
    if [[ "$env" == "dev" ]]; then
        echo "$dev 环境，没有supervisor配置"
    elif [[ "$env" == "test" || "$env" == "prod" ]]; then
        supervisorctl reread
        supervisorctl update
        echo -e "$BOLD_WHITE 判断服务进程是否存在...$RESET"
        echo "supervisorctl status ${service_name}"
        supervisorctl status "${service_name}"
        echo -e "$GREEN restart... $RESET"
        echo "supervisorctl restart ${service_name}"
        supervisorctl restart "${service_name}"
        echo "supervisorctl status ${service_name}"
        supervisorctl status "${service_name}"
    fi
}

function mySystemdServiceRestart() {
   if [[ "$env" == "dev" ]]; then
     echo "$dev 环境，没有systemd配置"
   elif [[ "$env" == "test" || "$env" == "prod" ]]; then
       echo -e "$BOLD_WHITE 判断服务进程是否存在...$RESET"
       echo "systemctl status ${service_name}"
       systemctl status "${service_name}"
       echo -e "$GREEN restart... $RESET"
       echo "systemctl restart ${service_name}"
       systemctl restart "${service_name}"
       echo "systemctl status ${service_name}"
       systemctl status "${service_name}"
   fi
}

if [[ "$damonMode" == "supervisor" ]]; then
  mySupervisorServiceRestart
elif [[ "$damonMode" == "systemd" ]]; then
  mySystemdServiceRestart
fi
